#ifndef __DEMO_BASE_H__
#define __DEMO_BASE_H__

class timer
{
public:
	timer();
	double get_time();

private:
	LARGE_INTEGER m_freq;

};

class demo_base
{
	typedef void (*func_render)();
	typedef LRESULT (CALLBACK *func_msg_proc)(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

private:
	IDirect3D9 *m_d3d;
	IDirect3DDevice9 *m_device;
	ID3DXFont *m_font;
	char m_fps_string[256];
	unsigned long m_frame_count;
	double m_last_time;
	timer m_timer;
	HWND m_wnd;

	func_render m_render;
	func_msg_proc m_msg_proc;

public:

	bool init(HINSTANCE instance, const char *title, int width, int height, D3DDEVTYPE device_type = D3DDEVTYPE_HAL);
	void release();

	void main_loop();

	void register_render(func_render render);
	void register_msg_proc(func_msg_proc msg_proc);
	IDirect3DDevice9* get_device();
	double get_time();

	static demo_base& get_instance();

private:

	demo_base() {}
	demo_base& operator = (const demo_base& other) {}

	bool init_wnd(HINSTANCE instance, const char *title, int width, int height);
	bool init_d3d(D3DDEVTYPE device_type);
	void cleanup();
	void update_fps();
	void display();
	
};

#endif //__DEMO_BASE_H__

